package com.xjscrm.console.service.customer.materialLibrary.impl;

import com.xjscrm.common.exception.BusinessException;
import com.xjscrm.common.result.ResponseCode;
import com.xjscrm.console.param.materialLibrary.BatchdelMaterialLibraryDto;
import com.xjscrm.console.service.customer.materialLibrary.MaterialLibraryService;
import com.xjscrm.console.service.customer.materialLibrary.MaterialLibrarybBtchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class MaterialLibrarybBtchServiceImpl implements MaterialLibrarybBtchService {

    @Autowired
    private MaterialLibraryService materialLibraryService;

    @Override
    public void batchdelMaterialLibraryTag(BatchdelMaterialLibraryDto batchdelMaterialLibraryDto) {

        if (batchdelMaterialLibraryDto.getIds() == null || batchdelMaterialLibraryDto.getIds().isEmpty()) {
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "id列表为空");
        }

        for (Long id : batchdelMaterialLibraryDto.getIds()) {
            try {
                batchdelMaterialLibraryDto.setId(id);
                materialLibraryService.delMaterialLibraryTag(batchdelMaterialLibraryDto);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    @Override
    public void batchDelMaterialLibrary(BatchdelMaterialLibraryDto batchdelMaterialLibraryDto) {

        if (batchdelMaterialLibraryDto.getIds() == null || batchdelMaterialLibraryDto.getIds().isEmpty()) {
            throw new BusinessException(ResponseCode.BUSINESS_EXCEPTION, "id列表为空");
        }

        for (Long id : batchdelMaterialLibraryDto.getIds()) {
            try {
                batchdelMaterialLibraryDto.setId(id);
                materialLibraryService.delMaterialLibrary(batchdelMaterialLibraryDto);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
